/**
 * @param {string} tiles
 * @return {number}
 */
var numTilePossibilities = function (tiles) {
  let arr = [], res = new Set(),visited=new Array(tiles.length).fill(false)
  bc(0)

  function bc(index) {
    if (arr.length) {
      res.add([...arr].join(''))
      // return
    }

    for(let i=0;i<tiles.length;i++){
      if(visited[i]) continue
      arr.push(tiles[i])
      visited[i]=true
      bc(i+1)
      arr.pop()
      visited[i]=false
    }
  }

  return res.size
};

numTilePossibilities('AAABBC')